home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 November: Tool Chest / Dev.CD Nov 94.toast / Sample Code / Snippets / Networking / Get Ethernet Address / GetEAddr.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-07-15  |  3.5 KB  |  140 lines  |  [TEXT/MPS ]

  1. /*
  2.     File: GetEAddr.c
  3.     Rich Kubota
  4.     DTS
  5.     June 2, 1992
  6.     
  7.     Sample program to demonstrate the use of the LAP Manager to determine the
  8.     current AppleTalk connection device based on the ADEV resource ID.  Also 
  9.     demonstrates a call to EGetInfo to obtain the burned in Ethernet address
  10.     whether on the card or built-in on the Quadra's.  This program assumes the 
  11.     use of the Apple Ethernet phase 1 0r 2 driver ADEV's.
  12.     
  13. */
  14.  
  15. #include <Types.h>
  16. #include <QuickDraw.h>
  17. #include <Fonts.h>
  18. #include <Events.h>
  19. #include <Dialogs.h>
  20. #include <Resources.h>
  21. #include <OSUtils.h>
  22. #include <Files.h>
  23. #include <ENET.h>
  24. #include <Devices.h>
  25. #include <Memory.h>
  26. #include <Menus.h>
  27. #include <OSEvents.h>
  28. #include <AppleTalk.h>
  29.  
  30.  
  31. #define LGetATalkInfo   0x09    /* Get AppleTalk info */
  32. #define kSPConfig        0x1FB    /* low nibble of global byte indicates whether AppleTalk active */
  33.  
  34. #define kAlertID        1000
  35. #define    ETalkPh1        2        /* Ethernet Phase 1 ADEV resource ID */
  36. #define    ETalkPh2        10        /* Ethernet Phase 2 ADEV resource ID */
  37.  
  38. #define kAlertID        1000
  39. #define kAddrID            1001
  40.  
  41. Boolean        SlotMgrAvailable();
  42. void         doInitializing();
  43. pascal long CallLAPMgr( short selector);    /* prototype for assembler routine */
  44.  
  45. main()
  46. {
  47.     
  48.     EParamBlock    pb;
  49.     OSErr        err;
  50.     long        result;
  51.     char        adevType;
  52.     char        slot;
  53.     char        buffer[78], c1, c2;
  54.     Str32        enetAddrStr;
  55.     short        i;
  56.     Ptr            spConfigPtr;
  57.     
  58.     
  59.     
  60.     doInitializing();                 /* set up to display alert dialogs */
  61.     result = CallLAPMgr(LGetATalkInfo); /* get current connection setting */
  62.     adevType = result & 0x000000FF;  /* atlk resource id is return in LSB */
  63.     slot = result>>24;                 /* card slot returned in MSB */
  64.  
  65.     spConfigPtr = (Ptr)kSPConfig;
  66.     if ((*spConfigPtr & 0x0F) != 1)     /* Check whether AppleTalk is enabled */
  67.     {
  68.         ParamText("\pAppleTalk must be active.\
  69.     Go to the Chooser and turn AppleTalk on.", nil, nil, nil);
  70.         err = StopAlert(kAlertID, nil);
  71.         ExitToShell();
  72.     }
  73.     if ((adevType != ETalkPh1) && (adevType != ETalkPh2)) 
  74.                             /* check whether Ethernet is the current setting */
  75.     {
  76.         ParamText("\pEthernet is not the default connection.  Use the Network CDEV and select the Ethernet driver.", nil, nil, nil);
  77.         err = StopAlert(kAlertID, nil);
  78.         ExitToShell();
  79.     }
  80.     
  81.     /* now we know that AppleTalk is active and that EtherTalk is already open */
  82.     if ((err = OpenDriver("\p.ENET", &pb.EParms1.ioRefNum)) == noErr) 
  83.     {
  84.         pb.EParms1.ePointer = buffer;
  85.         pb.EParms1.eBuffSize = sizeof(buffer);
  86.         err = EGetInfo(&pb, false);
  87.         enetAddrStr[0] = 12;
  88.             /* set up the address string to display in hexidecimal */
  89.         for (i=0; i<6; i++)
  90.         {
  91.             c1 = ((buffer[i] >> 4) & 0x0F) + '0';
  92.             c2 = (buffer[i] & 0x0F) + '0';
  93.             if (c1 > '9')
  94.                 c1 = c1 + ('A' - '9' - 1);
  95.             if (c2 > '9')
  96.                 c2 = c2 + ('A' - '9' - 1);
  97.             enetAddrStr[2*i+1] = c1;
  98.             enetAddrStr[2*i+2] = c2;
  99.         }
  100.             /* display the address in an alert dialog */
  101.         ParamText(enetAddrStr, nil, nil, nil);
  102.         err = Alert(kAddrID, nil);
  103.     }
  104.     else
  105.     {
  106.         ParamText("\pError opening the Ethernet driver.", nil, nil, nil);
  107.         err = StopAlert(kAlertID, nil);
  108.         ExitToShell();
  109.     }
  110. }
  111.  
  112.  
  113. /*    
  114.  *    doInitializing() Called at application boot to allocate master pointers,
  115.  *    check SysEnvirons() for Mac type, check for WaitNextEvent implementation.
  116.  *    and call all other initializing routines.
  117.  */
  118. void doInitializing()
  119. {
  120.     MaxApplZone();
  121.  
  122.     MoreMasters();
  123.     MoreMasters();
  124.     MoreMasters();
  125.     MoreMasters();
  126. #ifdef THINK_C
  127.     InitGraf(&thePort);
  128. #else
  129.     InitGraf(&qd.thePort);
  130. #endif
  131.     
  132.     InitFonts();
  133.     FlushEvents(everyEvent, 0);
  134.     InitWindows();
  135.     InitMenus();
  136.     TEInit();
  137.     InitDialogs(0L);    
  138.     InitCursor();
  139. }
  140.